-- wear_multi_bonus
-- create by zhuangsl
-- 首次穿戴奖励多种物品

return {
    apply = function(prop, baseValue)
        -- 数量
        return prop[3];
    end,

    record = function(target, prop, path)
        return false;
    end,

    -- 穿戴装备触发
    trigger = function(who, prop, classId)
        -- 预先处理一下
        if not EquipM.doWearTrigger(who, classId, prop[1], prop[2]) then
            return 0;
        end

        -- 随机分成几份
        local itemList = string.explode(prop[2], "+");
        local weights  = {};
        local ret      = {};
        local count    = #itemList;
        local amount   = prop[3];
        local total    = 0;
        local seed;

        for i = 1, count do
            seed = 1 + DungeonM.getRandSeed("wear_multi_bonus") % 1000;
            total = total + seed;
            weights[#weights + 1] = seed;
        end

        for i = 1, count do
            if i ~= count then
                seed = math.modf(weights[i] * prop[3] / total + 0.5)
                if seed > 0 then
                    ret[#ret + 1] = {1, tonumber(itemList[i]), seed};
                    amount = amount - seed;
                end
            elseif amount > 0 then
                ret[#ret + 1] = {1, tonumber(itemList[i]), amount};
            end
        end

        for i = 1, #ret do
           BonusM.doBonus(ret[i], "wear_multi_bonus");
        end
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        -- 描述内容诡异，单独处理
        if prop[2] == "7516+7517+7518" then
            desc = string.gsub(desc, "{0}", getLocStr("component"));
        end

        local num = prop[3];
        desc = string.gsub(desc, "{1}", num);

        return desc;
    end,
};
